<template>
  <div class="products">
    <template v-if="imgSrc != null && imgSrc.length !== 0">
      <div
        :key="index"
        @click="toProductInfo(item.id)"
        v-for="(item, index) in imgSrc"
        class="product"
      >
        <div class="p-title">{{item.name}}</div>
        <img width="210" :src="baseUrl + item.img">
        <div class="p-price">￥{{item.price}}</div>
        <div class="p-desc">{{item.pdesc}}</div>
      </div>
    </template>
    <div class="null" v-if="imgSrc == null || imgSrc.length === 0">没有找到任何商品</div>
  </div>
</template>

<script>
export default {
  name: "product",
  props: ["pTitle", "imgSrc"],
  methods: {
    toProductInfo(id) {
      this.$router.push({ path: "ProductInfo", query: { id: id } });
    }
  }
};
</script>

<style scoped>
.products {
  display: flex;
  flex-wrap: wrap;
}

.product {
  width: 230px;
  background-color: #fff;
  padding: 10px;
  margin: 0 10px 30px;
  cursor: pointer;
  border: 1px solid #fff;
  height: 100%;
}

.product:hover {
  border: 1px solid #409eff;
}

.p-title {
  text-align: center;
  margin-bottom: 5px;
  color: #409eff;
  font-weight: bold;
}

.p-desc {
  font-size: 13px;
  line-height: 1.5;
}

.p-price {
  color: red;
  font-weight: bold;
}

.null {
  font-size: 37px;
  text-align: center;
  padding: 100px 0;
  color: #888;
}
</style>